package com.zzptc.myk.myapplication.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.zzptc.myk.myapplication.Bean.CollectionItem;
import com.zzptc.myk.myapplication.R;

import java.util.List;

public class CollectionAdapter extends ArrayAdapter<CollectionItem> {
    int resoutceid;
    public CollectionAdapter(@NonNull Context context, int resource, @NonNull List<CollectionItem> objects) {
        super(context, resource, objects);
        this.resoutceid=resource;
    }
    @Override
    public View getView (int position, View convertView , ViewGroup parent){
        View view=convertView;
        if (view == null){
            view= LayoutInflater.from(getContext()).inflate(resoutceid,null);
        }
        ImageView bookimg=view.findViewById(R.id.bookimg);
        TextView bookname=view.findViewById(R.id.bookname);
        TextView authorname=view.findViewById(R.id.authorname);
        ImageView iscollexted=view.findViewById(R.id.iscollected);

        CollectionItem item=getItem(position);
        bookimg.setImageResource(item.getBookimg());
        bookname.setText(item.getBookname());
        authorname.setText(item.getAuthorname());
        if (item.isIscollected()){
            iscollexted.setImageResource(R.mipmap.hong);
        }else {
            iscollexted.setImageResource(R.mipmap.hei);
        }
        return view;
    }
}
